Gross Domestic Product Data Analysis

John Hios
12/09/2022

Table of Contents

  • 1  Introduction
    • 1.1  Background Information
    • 1.2  Scope of Work
    • 1.3  Provided Data
  • 2  Data Wrangling
    • 2.1  Import Data
    • 2.2  Inspect & Tidy Data
  • 3  Exploratory Data Analysis (EDA)
    • 3.1  Interactive Plot of GDP Over Time
    • 3.2  GDP Data Plotted on the World Map
  • 4  Insights

Introduction¶

Background Information¶

The World Bank, as part of its mission, has maintained detailed records concerning the economic activity of countries around the world for over half a century. In particular, the World Bank keeps records of the Gross Domestic Product (GDP) by country spanning the years from 1960 to 2021. The World Bank site includes lots of tools for visually analysing this GDP data. This page at the World Bank data site allows users to plot the yearly GDP of a particular country in terms of current US dollars.

The raw economic data collected by the World Bank are freely available for download and analysis. In particular, the yearly data on GDP in current US dollars are available as a comma-separated values (CSV) file.

Scope of Work¶

The scope of this assingment is to carry out wranging and exploratory data analysis on the GDP data using the Python data manipulation and analysis package Pandas with an aim to:

  1. Plot the yearly GDP of a specified list of countries as a line chart (XY plot) using the Python visualisation package Pygal.

  2. Plot the GDP data for a given year on a world map using Pygal. The plot should have a graphical functionality similar to this page at the World Bank data site. The map should depict not only the GDP data, but also the countries which are missing from the GDP data entirely and the countries that are contained within the GDP data, but have no data for the given year.

Provided Data¶

A CSV file containing GDP data up until the end of 2021 is available here. Note that the first two columns correspond to the Country Name and Country Code for each country in the file. Subsequent fields include GDP data (in current US dollars) for years 1960-2021 inclusive.

The World Bank data set uses the three-letter Country Code as per ISO3166-1-Alpha-3, while the list of countries supported in Pygal uses two-letter country codes as per ISO3166-1-Alpha-2. To reconcile Pygal's country information with the World Bank's country information an additional CSV file from the WorldData site is used. WorldData is a comprehensive database for geodetic, climatological and demographic data. It provides a wide variety of analyses and global comparisons as well as data sheets for each country with additional development data and charts for several areas of expertise. The file, which has been slightly edited for consistency (the second line has been deleted), can be found here.

Data Wrangling¶

Load libraries:

In [97]:
import pandas as pd
import numpy as np
import pygal
from pygal_maps_world.maps import World
from pygal_maps_world.maps import COUNTRIES
import os
import pprint

Import Data¶

Load GDP data set:

In [98]:
gdp_wide_df = pd.read_csv(r"..\clean_data\gdp_data_clean.csv")
gdp_wide_df
Out[98]:
Country Name Country Code Indicator Name Indicator Code 1960 1961 1962 1963 1964 1965 ... 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021
0 Aruba ABW GDP (current US$) NY.GDP.MKTP.CD NaN NaN NaN NaN NaN NaN ... 2.615084e+09 2.727933e+09 2.791061e+09 2.963128e+09 2.983799e+09 3.092179e+09 3.202235e+09 3.310056e+09 2.496648e+09 NaN
1 Africa Eastern and Southern AFE GDP (current US$) NY.GDP.MKTP.CD 2.129059e+10 2.180847e+10 2.370702e+10 2.821004e+10 2.611879e+10 2.968217e+10 ... 9.730430e+11 9.839370e+11 1.003680e+12 9.242530e+11 8.823550e+11 1.020650e+12 9.910220e+11 9.975340e+11 9.216460e+11 1.082100e+12
2 Afghanistan AFG GDP (current US$) NY.GDP.MKTP.CD 5.377778e+08 5.488889e+08 5.466667e+08 7.511112e+08 8.000000e+08 1.006667e+09 ... 1.990732e+10 2.014640e+10 2.049713e+10 1.913421e+10 1.811656e+10 1.875347e+10 1.805323e+10 1.879945e+10 2.011614e+10 NaN
3 Africa Western and Central AFW GDP (current US$) NY.GDP.MKTP.CD 1.040414e+10 1.112789e+10 1.194319e+10 1.267633e+10 1.383837e+10 1.486223e+10 ... 7.275700e+11 8.207930e+11 8.649900e+11 7.607340e+11 6.905460e+11 6.837490e+11 7.416900e+11 7.945430e+11 7.844460e+11 8.358080e+11
4 Angola AGO GDP (current US$) NY.GDP.MKTP.CD NaN NaN NaN NaN NaN NaN ... 1.249980e+11 1.334020e+11 1.372440e+11 8.721929e+10 4.984049e+10 6.897276e+10 7.779294e+10 6.930910e+10 5.361907e+10 7.254699e+10
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
261 Kosovo XKX GDP (current US$) NY.GDP.MKTP.CD NaN NaN NaN NaN NaN NaN ... 6.163785e+09 6.735731e+09 7.074658e+09 6.295820e+09 6.682833e+09 7.180813e+09 7.878509e+09 7.899879e+09 7.716925e+09 9.007159e+09
262 Yemen, Rep. YEM GDP (current US$) NY.GDP.MKTP.CD NaN NaN NaN NaN NaN NaN ... 3.540134e+10 4.041524e+10 4.322859e+10 4.244450e+10 3.131783e+10 2.684223e+10 2.160616e+10 2.188761e+10 1.884051e+10 2.106169e+10
263 South Africa ZAF GDP (current US$) NY.GDP.MKTP.CD 8.748597e+09 9.225996e+09 9.813996e+09 1.085420e+10 1.195600e+10 1.306899e+10 ... 4.344010e+11 4.008860e+11 3.811990e+11 3.467100e+11 3.235860e+11 3.814490e+11 4.048420e+11 3.879350e+11 3.354420e+11 4.199460e+11
264 Zambia ZMB GDP (current US$) NY.GDP.MKTP.CD 7.130000e+08 6.962857e+08 6.931429e+08 7.187143e+08 8.394286e+08 1.082857e+09 ... 2.550306e+10 2.803724e+10 2.714102e+10 2.125122e+10 2.095841e+10 2.587360e+10 2.631159e+10 2.330867e+10 1.811063e+10 2.120306e+10
265 Zimbabwe ZWE GDP (current US$) NY.GDP.MKTP.CD 1.052990e+09 1.096647e+09 1.117602e+09 1.159512e+09 1.217138e+09 1.311436e+09 ... 1.711485e+10 1.909102e+10 1.949552e+10 1.996312e+10 2.054868e+10 1.758489e+10 1.811554e+10 1.928429e+10 1.805117e+10 2.621773e+10

266 rows × 66 columns

Load GDP country codes data set:

In [99]:
# Disable the NA filter so that Namibia's country code "NA" is not parsed as a missing value
country_codes_df = pd.read_csv(r"..\clean_data\country_codes_clean.csv", 
                               keep_default_na = False, na_values = "")
country_codes_df
Out[99]:
Country ISO3166-1-Alpha-2 ISO3166-1-Alpha-3 ISO3166-1-numeric IOC Fips 10 License Plate Domain
0 Afghanistan AF AFG 4.0 AFG AF AFG .af
1 Åland Islands AX ALA 248.0 NaN NaN AX .ax
2 Albania AL ALB 8.0 ALB AL AL .al
3 Algeria DZ DZA 12.0 ALG AG DZ .dz
4 American Samoa AS ASM 16.0 ASA AQ USA .as
... ... ... ... ... ... ... ... ...
244 Wallis and Futuna WF WLF 876.0 NaN WF NaN .wf
245 Western Sahara EH ESH 732.0 NaN WI WSA .eh
246 Yemen YE YEM 887.0 YEM YM YEM .ye
247 Zambia ZM ZMB 894.0 ZAM ZA Z .zm
248 Zimbabwe ZW ZWE 716.0 ZIM ZI ZW .zw

249 rows × 8 columns

Inspect & Tidy Data¶

GDP data set¶

The GDP data set is in a wide format and should be re-formatted in a long format for further analysis.

In [100]:
gdp_df = gdp_wide_df.melt(
    id_vars = ["Country Name", "Country Code", "Indicator Name", "Indicator Code"], 
    var_name = "year",
    value_name = "gdp"
)

gdp_df
Out[100]:
Country Name Country Code Indicator Name Indicator Code year gdp
0 Aruba ABW GDP (current US$) NY.GDP.MKTP.CD 1960 NaN
1 Africa Eastern and Southern AFE GDP (current US$) NY.GDP.MKTP.CD 1960 2.129059e+10
2 Afghanistan AFG GDP (current US$) NY.GDP.MKTP.CD 1960 5.377778e+08
3 Africa Western and Central AFW GDP (current US$) NY.GDP.MKTP.CD 1960 1.040414e+10
4 Angola AGO GDP (current US$) NY.GDP.MKTP.CD 1960 NaN
... ... ... ... ... ... ...
16487 Kosovo XKX GDP (current US$) NY.GDP.MKTP.CD 2021 9.007159e+09
16488 Yemen, Rep. YEM GDP (current US$) NY.GDP.MKTP.CD 2021 2.106169e+10
16489 South Africa ZAF GDP (current US$) NY.GDP.MKTP.CD 2021 4.199460e+11
16490 Zambia ZMB GDP (current US$) NY.GDP.MKTP.CD 2021 2.120306e+10
16491 Zimbabwe ZWE GDP (current US$) NY.GDP.MKTP.CD 2021 2.621773e+10

16492 rows × 6 columns

Clean the variable names and make changes persist.

In [101]:
gdp_df.rename(
    columns = {
        "Country Name": "country_name", 
        "Country Code": "country_code", 
        "Indicator Name": "indicator_name", 
        "Indicator Code": "indicator_code"
        },
    inplace = True
)

gdp_df
Out[101]:
country_name country_code indicator_name indicator_code year gdp
0 Aruba ABW GDP (current US$) NY.GDP.MKTP.CD 1960 NaN
1 Africa Eastern and Southern AFE GDP (current US$) NY.GDP.MKTP.CD 1960 2.129059e+10
2 Afghanistan AFG GDP (current US$) NY.GDP.MKTP.CD 1960 5.377778e+08
3 Africa Western and Central AFW GDP (current US$) NY.GDP.MKTP.CD 1960 1.040414e+10
4 Angola AGO GDP (current US$) NY.GDP.MKTP.CD 1960 NaN
... ... ... ... ... ... ...
16487 Kosovo XKX GDP (current US$) NY.GDP.MKTP.CD 2021 9.007159e+09
16488 Yemen, Rep. YEM GDP (current US$) NY.GDP.MKTP.CD 2021 2.106169e+10
16489 South Africa ZAF GDP (current US$) NY.GDP.MKTP.CD 2021 4.199460e+11
16490 Zambia ZMB GDP (current US$) NY.GDP.MKTP.CD 2021 2.120306e+10
16491 Zimbabwe ZWE GDP (current US$) NY.GDP.MKTP.CD 2021 2.621773e+10

16492 rows × 6 columns

View the GDP dataframe information.

In [102]:
gdp_df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 16492 entries, 0 to 16491
Data columns (total 6 columns):
 #   Column          Non-Null Count  Dtype  
---  ------          --------------  -----  
 0   country_name    16492 non-null  object 
 1   country_code    16492 non-null  object 
 2   indicator_name  16492 non-null  object 
 3   indicator_code  16492 non-null  object 
 4   year            16492 non-null  object 
 5   gdp             13118 non-null  float64
dtypes: float64(1), object(5)
memory usage: 773.2+ KB

Change year type from object to integer.

In [103]:
gdp_df["year"] = gdp_df["year"].astype(int)

Check if there are any missing values.

In [104]:
gdp_df.isna().sum()
Out[104]:
country_name         0
country_code         0
indicator_name       0
indicator_code       0
year                 0
gdp               3374
dtype: int64

The GDP data set is cleaned up and in a tidy format now.

Country code data set¶

View the Country code dataframe information.

In [105]:
country_codes_df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 249 entries, 0 to 248
Data columns (total 8 columns):
 #   Column             Non-Null Count  Dtype  
---  ------             --------------  -----  
 0   Country            249 non-null    object 
 1   ISO3166-1-Alpha-2  249 non-null    object 
 2   ISO3166-1-Alpha-3  249 non-null    object 
 3   ISO3166-1-numeric  248 non-null    float64
 4   IOC                205 non-null    object 
 5   Fips 10            245 non-null    object 
 6   License Plate      213 non-null    object 
 7   Domain             249 non-null    object 
dtypes: float64(1), object(7)
memory usage: 15.7+ KB

The Country code dataframe is already in a tidy format, only columns ISO3166-1-Alpha-2 and ISO3166-1-Alpha-3 are of interest.

In [106]:
country_codes_trimmed_df = country_codes_df.loc[:, ["ISO3166-1-Alpha-2", "ISO3166-1-Alpha-3"]].copy()
country_codes_trimmed_df
Out[106]:
ISO3166-1-Alpha-2 ISO3166-1-Alpha-3
0 AF AFG
1 AX ALA
2 AL ALB
3 DZ DZA
4 AS ASM
... ... ...
244 WF WLF
245 EH ESH
246 YE YEM
247 ZM ZMB
248 ZW ZWE

249 rows × 2 columns

Check if there are any missing values.

In [107]:
country_codes_trimmed_df.isna().sum()
Out[107]:
ISO3166-1-Alpha-2    0
ISO3166-1-Alpha-3    0
dtype: int64

Data Transformations¶

Map the country codes from country_codes_trimmed_df to the country codes from gdp_df, and rename variable ISO3166-1-Alpha-2.

In [108]:
gdp_join_df = gdp_df \
    .reset_index() \
    .merge(country_codes_trimmed_df, how = "left", left_on = "country_code", right_on = "ISO3166-1-Alpha-3") \
    .drop(columns = ["index", "ISO3166-1-Alpha-3", "indicator_name", "indicator_code"])

gdp_join_df.rename(columns={"ISO3166-1-Alpha-2": "plot_code"}, inplace = True)
gdp_join_df.head()
Out[108]:
country_name country_code year gdp plot_code
0 Aruba ABW 1960 NaN AW
1 Africa Eastern and Southern AFE 1960 2.129059e+10 NaN
2 Afghanistan AFG 1960 5.377778e+08 AF
3 Africa Western and Central AFW 1960 1.040414e+10 NaN
4 Angola AGO 1960 NaN AO

Convert the values of country_code_short column into lowercase to compare with the Pygal country codes.

In [109]:
gdp_join_df["plot_code"] = gdp_join_df["plot_code"].str.lower()

gdp_join_df.head()
Out[109]:
country_name country_code year gdp plot_code
0 Aruba ABW 1960 NaN aw
1 Africa Eastern and Southern AFE 1960 2.129059e+10 NaN
2 Afghanistan AFG 1960 5.377778e+08 af
3 Africa Western and Central AFW 1960 1.040414e+10 NaN
4 Angola AGO 1960 NaN ao

Get the Pygal country code mapping and all World Bank GDP data country codes.

In [110]:
pygal_countries_dict = COUNTRIES
groupby_plot_code = gdp_join_df.groupby("plot_code")

# Compare number of country codes included in Pygal and the World Bank data
{"pygal_country_codes": len(COUNTRIES), "world_bank_country_codes": len(groupby_plot_code)}
Out[110]:
{'pygal_country_codes': 184, 'world_bank_country_codes': 216}

The country codes listed in Pygal are less than the codes listed in the World Bank GDP data.

Check which Pygal country codes have no match against the World Bank country codes

In [111]:
pygal_notin_wbd = {}
for country_code_key in pygal_countries_dict.keys():
    if country_code_key not in list(groupby_plot_code.groups):
        pygal_notin_wbd[country_code_key] = pygal_countries_dict[country_code_key]
pprint.pprint(pygal_notin_wbd)

print("\n")
print("Number of country codes: " + str(len(pygal_notin_wbd )))
{'aq': 'Antarctica',
 'eh': 'Western Sahara',
 'gf': 'French Guiana',
 're': 'Reunion',
 'sh': 'Saint Helena, Ascension and Tristan da Cunha',
 'tw': 'Taiwan, Province of China',
 'va': 'Holy See (Vatican City State)',
 'yt': 'Mayotte'}


Number of country codes: 8
Out of the 8 country codes in the dictionary above: - Antarctica is a continent and not a country. - Western Sahara is administered by the Kingdom of Morocco. - French Guiana, Reunion and Mayotte are overseas departments and regions of France. - Saint Helena, Ascension and Tristan da Cunha is a British Overseas Territory. - Taiwan is currently not in the UN and is classified as only a territory. - The Holy See's GDP is not published.

Find the countries that are missing from Pygal's list of country codes.

In [112]:
groupby_code_country = gdp_join_df.groupby(["plot_code", "country_name"])

wbd_notin_pygal = {}
for country_code_key in list(groupby_code_country.groups):
    if country_code_key[0] not in pygal_countries_dict.keys():
        wbd_notin_pygal[country_code_key[0]] = country_code_key[1]

pprint.pprint(wbd_notin_pygal) 

print("\n")
print("Number of country codes: " + str(len(wbd_notin_pygal)))
{nan: 'World',
 'ag': 'Antigua and Barbuda',
 'as': 'American Samoa',
 'aw': 'Aruba',
 'bb': 'Barbados',
 'bm': 'Bermuda',
 'bs': 'Bahamas, The',
 'cw': 'Curacao',
 'dm': 'Dominica',
 'fj': 'Fiji',
 'fm': 'Micronesia, Fed. Sts.',
 'fo': 'Faroe Islands',
 'gd': 'Grenada',
 'gi': 'Gibraltar',
 'im': 'Isle of Man',
 'ki': 'Kiribati',
 'km': 'Comoros',
 'kn': 'St. Kitts and Nevis',
 'ky': 'Cayman Islands',
 'lc': 'St. Lucia',
 'mf': 'St. Martin (French part)',
 'mh': 'Marshall Islands',
 'mp': 'Northern Mariana Islands',
 'nc': 'New Caledonia',
 'nr': 'Nauru',
 'pf': 'French Polynesia',
 'pw': 'Palau',
 'qa': 'Qatar',
 'sb': 'Solomon Islands',
 'ss': 'South Sudan',
 'sx': 'Sint Maarten (Dutch part)',
 'tc': 'Turks and Caicos Islands',
 'to': 'Tonga',
 'tt': 'Trinidad and Tobago',
 'tv': 'Tuvalu',
 'vc': 'St. Vincent and the Grenadines',
 'vg': 'British Virgin Islands',
 'vi': 'Virgin Islands (U.S.)',
 'vu': 'Vanuatu',
 'ws': 'Samoa',
 'xk': 'Kosovo'}


Number of country codes: 41
Out of the 41 items in the dictionary above, 40 correspond to real country codes (the NaN value corresponds to the "world"). Some of these codes correspond to countries that have not been included in the `Pygal` map (e.g. Qatar, Faroe Islands, South Sudan, etc) whereas, other codes correspond to overseas territories or regions of countries and may not have GDP data recorded.

Exploratory Data Analysis (EDA)¶

Code to enable embedding of interactive visualizations directly into this notebook.

In [113]:
from IPython.display import display, HTML

base_html = """
<!DOCTYPE html>
<html>
  <head>
  <script type="text/javascript" src="http://kozea.github.com/pygal.js/javascripts/svg.jquery.js"></script>
  <script type="text/javascript" src="https://kozea.github.io/pygal.js/2.0.x/pygal-tooltips.min.js""></script>
  </head>
  <body>
    <figure>
      {rendered_chart}
    </figure>
  </body>
</html>
"""

Interactive Plot of GDP Over Time¶

Functions for plotting GDP for a selection of countries:

In [114]:
# the oldest year for which there is data in the World Bank GDP data csv file
START_YEAR = 1960

def build_plot_dict(gdp_df, country_list):
    """
    Inputs:
      gdp_df       - GDP dataframe
      country_list - List of strings that are country names

    Output:
      Returns a dictionary whose keys are the country names in
      country_list and whose values are lists of XY plot (line chart)
      values computed from the GDP dataframe gdp_df in trillion
      US dollars.

      Countries from country_list that do not appear in the
      GDP dataframe should still be in the output dictionary, but
      with an empty XY plot value list.
    """
    gdp_plotdata_dict = {}
    for country in country_list:
        gdp_country_df = gdp_df.loc[gdp_df["country_name"] == country].copy()
        gdp_country_list = [gdp/1e12 for gdp in gdp_country_df["gdp"].tolist()]
        gdp_plotdata_dict[country] = gdp_country_list
        
    return gdp_plotdata_dict


def render_line_plot(gdp_df, country_list, min_year, max_year):
    """
    Inputs:
      gdp_df       - GDP dataframe
      country_list - List of strings that are country names
      min_year     - GDP plot oldest year 
      max_year     - GDP plot most recent year

    Output:
      Returns None.

    Action:
      Creates an SVG image of an XY plot (line chart) for the
      GDP data specified by gdp_df for the countries in country_list.
      The image is embedded in the notebook and it is also
      stored in a file in the outputs folder.
    """
    gdp_plotdata_dict = build_plot_dict(gdp_df, country_list)
    
    line_chart = pygal.Line(
        x_title = "Year", 
        y_title = "GDP ($ Trillion)", 
        x_label_rotation = 300,
        dots_size = 1.5,
        width = 800, 
        height=400
    )
    line_chart.title = "GDP Over Time for Selected Countries (Years " + str(min_year) + " to " + str(max_year) + ")"
    line_chart.x_labels = map(str, range(min_year, max_year + 1))
                          
    for country in gdp_plotdata_dict.keys():
        gdp_country = gdp_plotdata_dict[country]
        line_chart.add(country, gdp_country[(min_year - START_YEAR) : (max_year - START_YEAR + 1)])
    
    line_chart.value_formatter = lambda x: "%.2f" % x 
    line_chart.render_to_file("..\\outputs\\line_chart_" + str(min_year) + "_" + str(max_year)+ ".svg")
    display(HTML(base_html.format(rendered_chart=line_chart.render(is_unicode = True))))
    

Plot the World Bank GDP data (in trillion US dollar) for the G7 countries spanning 1970 to 2015. The output should be an SVG image of the resulting line plot.

In [115]:
# Alternatively, we can use gdp_join_df to get the same plots
render_line_plot(gdp_df, ["Canada", "France", "Germany", "Italy", "Japan", "United Kingdom", "United States"], 1970, 2021)
GDP Over Time for Selected Countries (Years 1970 to 2021)2.002.004.004.006.006.008.008.0010.0010.0012.0012.0014.0014.0016.0016.0018.0018.0020.0020.0022.0022.001970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021GDP Over Time for Selected Countries (Years 1970 to 2021)YearGDP ($ Trillion)0.0910.661538461538461271.8843251109201419700.1021.114027149321267271.7519588066682619710.1131.566515837104074271.591257545365919720.1342.019004524886874271.3790337967134319730.1652.471493212669685271.040585845781119740.1762.92398190045249270.8843764140326619750.2173.37647058823528270.5033999362443619760.2183.8289592760181270.444802491306919770.2294.28144796380089270.3631081583232619780.24104.7339366515837270.078742996125819790.27115.18642533936651269.7205725135872319800.31125.6389140271493269.344029242018419810.31136.09140271493214269.259181631120119820.34146.5438914027149268.9445403466575619830.36156.99638009049775268.772040918302219840.36167.44886877828054268.662863033900319850.38177.90135746606333268.515298936065419860.43188.35384615384615267.888378416648319870.51198.80633484162897267.003633793791219880.57209.25882352941176266.332229947925419890.59219.71131221719455265.9962604036196619900.61230.16380090497736265.805458000505219910.59240.6162895927602266.0142026713109519920.58251.06877828054297266.1912632987162519930.58261.5212669683258266.1799999296337719940.60271.97375565610855265.878716442388919950.63282.42624434389137265.5934786018018519960.65292.8787330316742265.2858187444565519970.63303.331221719457265.5300174293060419980.68313.78371040723977265.013252194087319990.74324.23619909502264264.241094719207720000.74334.6886877828054264.30847712660120010.76345.1411764705882264.0563661576852620020.90355.5936651583711262.486801713185420031.03366.0461538461538260.9607897381852720041.17376.4986425339366259.257088807339320051.32386.95113122171944257.5565295186960420061.47397.40361990950225255.8162924526031620071.55407.8561085972851254.8369145851717720081.37418.30859728506783256.912260152892620091.62428.76108597285065254.088156526846820101.79439.21357466063347252.040387596239120111.83449.66606334841623251.6326722525917620121.85460.11855203619905251.42055322534620131.81470.5710407239819251.8958720549120520141.56481.0235294117647254.7959568794172220151.53491.4760180995475255.1278073817237820161.65501.9285067873302253.7166282470905420171.73512.3809954751131252.8316160028606420181.74522.833484162896252.637415971882520191.65533.2859728506786253.7614257377595720201.99543.7384615384615249.7431490033083320210.1510.661538461538461271.1796675096685519700.1721.114027149321267270.9759145592516319710.2031.566515837104074270.5392612002032719720.2642.019004524886874269.830227462175519730.2952.471493212669685269.584457956224619740.3662.92398190045249268.708521567247119750.3773.37647058823528268.5748621450873719760.4183.8289592760181268.1331705228027419770.5194.28144796380089267.0111504636541319780.61104.7339366515837265.7632785450051619790.70115.18642533936651264.747073649530319800.62125.6389140271493265.744673041737719810.58136.09140271493214266.101586867395219820.56146.5438914027149266.39258438535419830.53156.99638009049775266.7321726360488619840.55167.44886877828054266.470904361897719850.77177.90135746606333263.9304444839138519860.93188.35384615384615262.037290892529419871.02198.80633484162897261.0520137191839519881.03209.25882352941176260.978010591741119891.27219.71131221719455258.139245968749119901.27230.16380090497736258.138082397562919911.40240.6162895927602256.599957646514319921.32251.06877828054297257.5151063844670619931.39261.5212669683258256.687109128361319941.60271.97375565610855254.2772368446056219951.61282.42624434389137254.2238289271586819961.45292.8787330316742256.001765699684719971.50303.331221719457255.4173038928523719981.49313.78371040723977255.533195582998719991.37324.23619909502264257.016865202532720001.38334.6886877828054256.877003945950520011.50345.1411764705882255.4370846030179220021.84355.5936651583711251.444522791781920032.12366.0461538461538248.243654815641920042.20376.4986425339366247.3439815744657420052.32386.95113122171944245.905923945431120062.66397.40361990950225241.949200126730320072.93407.8561085972851238.8109322804082820082.70418.30859728506783241.480280938688420092.65428.76108597285065242.1283900894063420102.87439.21357466063347239.5688825511042820112.68449.66606334841623241.6806478969534520122.81460.11855203619905240.1888332791159820132.86470.5710407239819239.6759311002354320142.44481.0235294117647244.5253467329951320152.47491.4760180995475244.1324087434126420162.60501.9285067873302242.710641110984920172.79512.3809954751131240.4322523712707220182.73522.833484162896241.1547137207873620192.63533.2859728506786242.301413124795520202.94543.7384615384615238.7275042263571520210.2210.661538461538461270.3956299729777619700.2521.114027149321267269.9983053200232319710.3031.566515837104074269.4186490621899619720.4042.019004524886874268.271693672520819730.4552.471493212669685267.7256413505452319740.4962.92398190045249267.198147988989619750.5273.37647058823528266.859350966701419760.6083.8289592760181265.919837048109519770.7494.28144796380089264.291163187350219780.88104.7339366515837262.651982278779519790.95115.18642533936651261.849746488736419800.80125.6389140271493263.592997204201619810.78136.09140271493214263.871044174857919820.77146.5438914027149263.9396017891492619830.73156.99638009049775264.469876085839919840.73167.44886877828054264.383492560975819851.05177.90135746606333260.7330788570443519861.30188.35384615384615257.8018103247487719871.40198.80633484162897256.6027502173612319881.40209.25882352941176256.6290469261695619891.77219.71131221719455252.292417115171819901.87230.16380090497736251.1604950652284719912.13240.6162895927602248.1047244160086519922.07251.06877828054297248.8057760556990619932.21261.5212669683258247.2494995941456519942.59271.97375565610855242.81955137401419952.50282.42624434389137243.849893659401319962.21292.8787330316742247.1689804680600619972.24303.331221719457246.8548162477838419982.19313.78371040723977247.367252998189919991.95324.23619909502264250.2409247567681820001.95334.6886877828054250.2664069657461420012.08345.1411764705882248.7224643587665620022.50355.5936651583711243.7986965272081420032.81366.0461538461538240.1600930708166320042.85376.4986425339366239.7818160781803820052.99386.95113122171944238.0615924364902320063.43397.40361990950225233.0479969093565620073.75407.8561085972851229.3282925412863420083.41418.30859728506783233.2146203032215820093.40428.76108597285065233.349478203703120103.75439.21357466063347229.2811679082449220113.53449.66606334841623231.8662740126435720123.73460.11855203619905229.461637799225820133.89470.5710407239819227.6547281041631520143.36481.0235294117647233.8391089588594720153.47491.4760180995475232.532883945222220163.69501.9285067873302229.9613916237021820173.98512.3809954751131226.628458317927620183.89522.833484162896227.6635712451783620193.85533.2859728506786228.151340286436820204.22543.7384615384615223.768051270872120210.1110.661538461538461271.5876272032649619700.1221.114027149321267271.456411280596319710.1531.566515837104074271.2168552447797719720.1842.019004524886874270.865084403765319730.2052.471493212669685270.584989547821319740.2362.92398190045249270.257653701717219750.2273.37647058823528270.2923164873543619760.2683.8289592760181269.9097459170409419770.3294.28144796380089269.24113464202219780.39104.7339366515837268.3263466111370719790.48115.18642533936651267.353833813704319800.43125.6389140271493267.895522743731619810.43136.09140271493214267.9354332354185419820.44146.5438914027149267.751949695065419830.44156.99638009049775267.8119201540025619840.45167.44886877828054267.645192038730819850.64177.90135746606333265.455711773354819860.81188.35384615384615263.5320144383324519870.89198.80633484162897262.532553332227119880.93209.25882352941176262.1014269363132619891.18219.71131221719455259.162723184137819901.25230.16380090497736258.406401913102519911.32240.6162895927602257.546057378020219921.06251.06877828054297260.5154910452233719931.10261.5212669683258260.1168515568284619941.17271.97375565610855259.2390534539530319951.31282.42624434389137257.636001430714119961.24292.8787330316742258.456900902583919971.27303.331221719457258.129122899429119981.25313.78371040723977258.3339114282017619991.15324.23619909502264259.564620671854120001.17334.6886877828054259.316314580717320011.28345.1411764705882258.050930915715920021.58355.5936651583711254.550327002008720031.81366.0461538461538251.8866798425409920041.86376.4986425339366251.2853462535086420051.95386.95113122171944250.222656689144720062.21397.40361990950225247.1560648278931520072.41407.8561085972851244.880585016144520082.20418.30859728506783247.3093071531167520092.14428.76108597285065248.0520146412734220102.29439.21357466063347246.2032163835072820112.09449.66606334841623248.623793522176120122.14460.11855203619905247.984294798236120132.16470.5710407239819247.750533346926920141.84481.0235294117647251.5364449154923520151.88491.4760180995475251.0660130849083820161.96501.9285067873302250.0801192188342320172.09512.3809954751131248.5659640342215720182.01522.833484162896249.504267838779820191.89533.2859728506786250.885659551046120202.10543.7384615384615248.47346012491820210.2110.661538461538461270.4332016865804519700.2421.114027149321267270.112719274763119710.3231.566515837104074269.2065416706560719720.4342.019004524886874267.87946546136219730.4852.471493212669685267.32626881230319740.5262.92398190045249266.83854631389219750.5973.37647058823528266.086646613364319760.7283.8289592760181264.512916584017819771.0194.28144796380089261.112984849341319781.06104.7339366515837260.631266378251119791.11115.18642533936651260.045059214639419801.22125.6389140271493258.72324234710719811.13136.09140271493214259.70611092809719821.24146.5438914027149258.4401454775025419831.32156.99638009049775257.566768945134719841.40167.44886877828054256.6299777831185319852.08177.90135746606333248.7169955741913719862.53188.35384615384615243.4360113884670819873.07198.80633484162897237.165875337347219883.05209.25882352941176237.361006225274319893.13219.71131221719455236.4544679140995519903.58230.16380090497736231.1997804371835319913.91240.6162895927602227.4252718662429219924.45251.06877828054297221.07996911649419935.00261.5212669683258214.742462293692719945.55271.97375565610855208.3805204759810319954.92282.42624434389137215.6199113252122619964.49292.8787330316742220.6342049950576719974.10303.331221719457225.2197226827853719984.64313.78371040723977218.964131271493119994.97324.23619909502264215.0966533627744820004.37334.6886877828054222.0041937096991720014.18345.1411764705882224.236621387558120024.52355.5936651583711220.3187608464766420034.89366.0461538461538215.9721243232774820044.83376.4986425339366216.689465959574820054.60386.95113122171944219.3634689025997520064.58397.40361990950225219.6184073494979420075.11407.8561085972851213.4872016980113520085.29418.30859728506783211.3600772125042220095.76428.76108597285065205.8961796363079820106.23439.21357466063347200.379921356732420116.27449.66606334841623199.9236850946201720125.21460.11855203619905212.2578887397824620134.90470.5710407239819215.9270941183712320144.44481.0235294117647221.1871340227437820155.00491.4760180995475214.6856800198057420164.93501.9285067873302215.5332252718397720175.04512.3809954751131214.2882041025970420185.12522.833484162896213.293583452626320195.04533.2859728506786214.261791036670120204.94543.7384615384615215.4566622877872520210.1310.661538461538461271.386597009423819700.1521.114027149321267271.1836469231253719710.1731.566515837104074270.9293949832270419720.1942.019004524886874270.6667420593642519730.2152.471493212669685270.5085778280229619740.2462.92398190045249270.0940439572244719750.2373.37647058823528270.200417635067619760.2683.8289592760181269.8460985731553619770.3494.28144796380089268.998820942494219780.44104.7339366515837267.799051056683119790.56115.18642533936651266.3334866048064719800.54125.6389140271493266.6148613890553619810.52136.09140271493214266.914096991012519820.49146.5438914027149267.210004779377119830.46156.99638009049775267.537328989769319840.49167.44886877828054267.2138794714271619850.60177.90135746606333265.908724943281219860.75188.35384615384615264.2365567915814519870.91198.80633484162897262.317129762812519880.93209.25882352941176262.122091960580319891.09219.71131221719455260.187247613594119901.14230.16380090497736259.60976723387919911.18240.6162895927602259.1808748946426719921.06251.06877828054297260.55703053657119931.14261.5212669683258259.6366457282803719941.35271.97375565610855257.2405035845219519951.42282.42624434389137256.3667779807982519961.56292.8787330316742254.7603516011192519971.65303.331221719457253.6686891142187819981.69313.78371040723977253.292041121243219991.66324.23619909502264253.566992992544220001.64334.6886877828054253.7789956626713220011.78345.1411764705882252.1480179309633320022.06355.5936651583711248.9713522354964820032.42366.0461538461538244.7275754051581220042.54376.4986425339366243.2961501318848420052.72386.95113122171944241.2921314778785420063.11397.40361990950225236.7644432781053820072.94407.8561085972851238.7110978726316320082.43418.30859728506783244.6811489148283820092.49428.76108597285065243.9212205731158720102.67439.21357466063347241.7828094471025220112.72449.66606334841623241.2676964829681820122.80460.11855203619905240.2887840440112720133.09470.5710407239819236.9856381606035720142.96481.0235294117647238.505262129791420152.72491.4760180995475241.224760706197120162.70501.9285067873302241.5020397198704820172.90512.3809954751131239.154302137458320182.88522.833484162896239.4116840838475520192.76533.2859728506786240.828564717293220203.19543.7384615384615235.8256740450726720211.0710.661538461538461260.418449208293619701.1621.114027149321267259.353199787320119711.2831.566515837104074258.023703349958619721.4342.019004524886874256.32174777589219731.5552.471493212669685254.9270913521028819741.6862.92398190045249253.302047833444619751.8773.37647058823528251.108599790323619762.0883.8289592760181248.6834847240285719772.3594.28144796380089245.5445187349948519782.63104.7339366515837242.336203903263119792.86115.18642533936651239.6602228892216119803.21125.6389140271493235.5908653796958619813.34136.09140271493214233.999681782556219823.63146.5438914027149230.6224164145870419834.04156.99638009049775225.9265921784068219844.34167.44886877828054222.419937694531319854.58177.90135746606333219.6198036349214219864.86188.35384615384615216.4131178028503719875.24198.80633484162897211.9773517267876719885.64209.25882352941176207.2632594229839419895.96219.71131221719455203.5216799166130419906.16230.16380090497736201.2528324606257719916.52240.6162895927602197.0383776241798219926.86251.06877828054297193.1028308010680219937.29261.5212669683258188.114833840030919947.64271.97375565610855184.0131290515285519958.07282.42624434389137178.9705606018583219968.58292.8787330316742173.1011584672685319979.06303.331221719457167.4546965719562519989.63313.78371040723977160.84153973514225199910.25324.23619909502264153.63054002285446200010.58334.6886877828054149.7791193965055200110.93345.1411764705882145.7392002379908200211.46355.5936651583711139.6036893731152200312.22366.0461538461538130.7512397884436200413.04376.4986425339366121.18668463781262200513.82386.95113122171944112.15271794809254200614.47397.40361990950225104.48943811572568200714.77407.8561085972851101.04875811810817200814.48418.30859728506783104.44405883946357200915.05428.7610859728506597.80123093740124201015.60439.2135746606334791.39344441495294201116.25449.6660633484162383.78019814359297201216.84460.1185520361990576.92443671445457201317.55470.571040723981968.69217057203193201418.21481.023529411764761.0672885888099201518.70491.476018099547555.37626191706585201619.48501.928506787330246.248045961262875201720.53512.380995475113134.05847421454632201821.37522.83348416289624.22164340634265201920.89533.285972850678629.79398581709347202023.00543.73846153846155.3310651982533272021CanadaFranceGermanyItalyJapanUnited KingdomUnited States

GDP Data Plotted on the World Map¶

Functions for creating the choropleth maps:

In [116]:
def reconcile_countries_by_code(gdp_join_df, country_codes_trimmed_df, year):
    """
    Inputs:
      gdp_join_df              - GDP dataframe reconciled with Pygal's country codes 
      country_codes_trimmed_df - Dataframe that maps World Bank's country information
                                 with Pygal's country information.  
      year                     - Integer year for which to create GDP mapping

    Output:
      A tuple containing a dictionary and two lists. The dictionary maps
      country codes from plot_countries to the log (base 10) of the GDP
      value for that country in the specified year. The first list 
      contains the country codes from countries which are entirely missing
      from the World Bank GDP data. The second list contains country codes
      from countries lacking a GDP for the specified year.
    """
    gdp_year_df = gdp_join_df.loc[gdp_join_df["year"] == year].copy()
    
    # Find all complete rows and make a dictionary of countries with gdp
    gdp_complete = gdp_year_df.loc[~ gdp_year_df.isna().any(axis='columns')].copy()
    gdp_complete_dict = dict(zip(gdp_complete["plot_code"], np.log10(gdp_complete["gdp"])))
    
    # Get list of countries with a GDP for the specified year
    codes_gdp_list = gdp_complete["plot_code"].tolist()
        
    # Get list of countries lacking a GDP for the specified year and remove NaN values from list
    codes_no_gdp_full = gdp_year_df.loc[gdp_year_df["gdp"].isna()].copy()
    codes_nogdp_list = \
        [x for x in codes_no_gdp_full["plot_code"].tolist() if pd.isnull(x) == False]
    
    # Get list of all country codes and remove NaN values from list and lowecase all items
    codes_trimmed_list = \
        [x.lower() for x in country_codes_trimmed_df["ISO3166-1-Alpha-2"].tolist() if pd.isnull(x) == False]
    
    # Get countries not listed in World Bank Data
    codes_dummy = list(set(codes_trimmed_list).difference(set(codes_gdp_list)))
    codes_wbd_missing_list = list(set(codes_dummy).difference(set(codes_nogdp_list)))
    
    return gdp_complete_dict, codes_wbd_missing_list, codes_nogdp_list




def render_world_map(gdp_join_df, country_codes_trimmed_df, year):
    """
    Inputs:
      gdp_join_df              - GDP dataframe reconciled with Pygal's country codes 
      country_codes_trimmed_df - Dataframe that maps World Bank's country information
                                 with Pygal's country information.  
      year                     - Integer year for which to create GDP mapping

    Output:
      Returns None.

    Action:
      Creates a world map plot of the GDP data (choropleth map). The image
      is embedded in the notebook and it is also stored in a file in the
      outputs folder.
    """      
    gdp_complete_dict, codes_wbd_missing_list, codes_nogdp_list = \
        reconcile_countries_by_code(gdp_join_df, country_codes_trimmed_df, year)
    
    worldmap_chart = World(width = 800, height=400, legend_at_bottom = True, legend_at_bottom_columns = 3)
    worldmap_chart.title = "GDP by Country for " + str(year) + " (log10 scale)"
    worldmap_chart.add("GDP for " + str(year), gdp_complete_dict)
    worldmap_chart.add("Missing from World Bank Data", codes_wbd_missing_list)
    worldmap_chart.add("No GDP Data", codes_nogdp_list)
    worldmap_chart.value_formatter = lambda x: "%.2f" % x
    worldmap_chart.render_to_file("..\\outputs\\map_file_" + str(year) + ".svg")
    # worldmap_chart.render_in_browser()
    display(HTML(base_html.format(rendered_chart=worldmap_chart.render(is_unicode=True))))

Plot the logarithmically-scaled (base 10) GDP data on a world map for a selection of years (1960, 1970, 2000 and 2015).

Each world map has three different coloured countries:

  • Red colour for countries with GDP data.
  • Blue colour for countries that are missing from the World Bank GDP data.
  • Green colour for countries that don't have GDP data for the given year.
In [117]:
# Year 1960
render_world_map(gdp_join_df, country_codes_trimmed_df, 1960)
GDP by Country for 1960 (log10 scale) Andorra: 1.0000 United Arab Emirates: 1.0000 Afghanistan: 8.7300 Albania: 1.0000 Armenia: 1.0000 Angola: 1.0000 Antarctica: 1.0000 Argentina: 1.0000 Austria: 9.8200 Australia: 10.2700 Azerbaijan: 1.0000 Bosnia and Herzegovina: 1.0000 Bangladesh: 9.6300 Belgium: 10.0700 Burkina Faso: 8.5200 Bulgaria: 1.0000 Bahrain: 1.0000 Burundi: 8.2900 Benin: 8.3500 Brunei Darussalam: 1.0000 Bolivia, Plurinational State of: 8.5700 Brazil: 10.2300 Bhutan: 1.0000 Botswana: 7.4800 Belarus: 1.0000 Belize: 7.4500 Canada: 10.6100 Congo, the Democratic Republic of the: 9.5300 Central African Republic: 8.0500 Congo: 8.1200 Switzerland: 9.9800 Cote d'Ivoire: 8.7400 Chile: 9.6100 Cameroon: 8.7900 China: 10.7800 Colombia: 9.6100 Costa Rica: 8.7100 Cuba: 1.0000 Cape Verde: 1.0000 Cyprus: 1.0000 Czech Republic: 1.0000 Germany: 1.0000 Djibouti: 1.0000 Denmark: 1.0000 Dominican Republic: 8.8300 Algeria: 9.4400 Ecuador: 9.3200 Estonia: 1.0000 Egypt: 1.0000 Western Sahara: 1.0000 Eritrea: 1.0000 Spain: 10.0800 Ethiopia: 1.0000 Finland: 9.7200 France: 10.7900 Gabon: 8.1500 United Kingdom: 10.8600 Georgia: 1.0000 French Guiana: 1.0000 Ghana: 9.0900 Greenland: 1.0000 Gambia: 1.0000 Guinea: 1.0000 Equatorial Guinea: 1.0000 Greece: 9.6400 Guatemala: 9.0200 Guam: 1.0000 Guinea-Bissau: 1.0000 Guyana: 8.2300 Hong Kong: 9.1200 Honduras: 8.5300 Croatia: 1.0000 Haiti: 8.4400 Hungary: 1.0000 Indonesia: 1.0000 Ireland: 9.2900 Israel: 9.4100 India: 10.5700 Iraq: 9.2300 Iran, Islamic Republic of: 9.6200 Iceland: 8.4000 Italy: 10.6100 Jamaica: 8.8400 Jordan: 1.0000 Japan: 10.6500 Kenya: 8.9000 Kyrgyzstan: 1.0000 Cambodia: 8.8000 Korea, Democratic People's Republic of: 1.0000 Korea, Republic of: 9.6000 Kuwait: 1.0000 Kazakhstan: 1.0000 Lao People's Democratic Republic: 1.0000 Lebanon: 1.0000 Liechtenstein: 1.0000 Sri Lanka: 9.1500 Liberia: 1.0000 Lesotho: 7.5400 Lithuania: 1.0000 Luxembourg: 8.8500 Latvia: 1.0000 Libyan Arab Jamahiriya: 1.0000 Morocco: 9.3100 Monaco: 1.0000 Moldova, Republic of: 1.0000 Montenegro: 1.0000 Madagascar: 8.8300 Macedonia, the former Yugoslav Republic of: 1.0000 Mali: 1.0000 Myanmar: 1.0000 Mongolia: 1.0000 Macao: 1.0000 Mauritania: 1.0000 Malta: 1.0000 Mauritius: 1.0000 Maldives: 1.0000 Malawi: 8.2100 Mexico: 10.1200 Malaysia: 9.2800 Mozambique: 1.0000 Namibia: 1.0000 Niger: 8.6500 Nigeria: 9.6200 Nicaragua: 8.3500 Netherlands: 10.0900 Norway: 9.7100 Nepal: 8.7100 New Zealand: 9.7400 Oman: 1.0000 Panama: 8.7300 Peru: 9.4100 Papua New Guinea: 8.3600 Philippines: 9.8800 Pakistan: 9.5700 Poland: 1.0000 Puerto Rico: 9.2300 Palestine, State of: 1.0000 Portugal: 9.5000 Paraguay: 1.0000 Reunion: 1.0000 Romania: 1.0000 Serbia: 1.0000 Russian Federation: 1.0000 Rwanda: 8.0800 Saudi Arabia: 1.0000 Seychelles: 7.0800 Sudan: 9.1200 Sweden: 10.2000 Singapore: 8.8500 Saint Helena, Ascension and Tristan da Cunha: 1.0000 Slovenia: 1.0000 Slovakia: 1.0000 Sierra Leone: 8.5100 San Marino: 1.0000 Senegal: 9.0000 Somalia: 8.2600 Suriname: 8.0000 Sao Tome and Principe: 1.0000 El Salvador: 1.0000 Syrian Arab Republic: 8.9300 Swaziland: 7.5500 Chad: 8.5000 Togo: 8.0800 Thailand: 9.4400 Tajikistan: 1.0000 Timor-Leste: 1.0000 Turkmenistan: 1.0000 Tunisia: 1.0000 Turkey: 10.1500 Taiwan, Province of China: 1.0000 Tanzania, United Republic of: 1.0000 Ukraine: 1.0000 Uganda: 8.6300 United States: 11.7400 Uruguay: 9.0900 Uzbekistan: 1.0000 Holy See (Vatican City State): 1.0000 Venezuela, Bolivarian Republic of: 9.8900 Viet Nam: 1.0000 Yemen: 1.0000 Mayotte: 1.0000 South Africa: 9.9400 Zambia: 8.8500 Zimbabwe: 9.0200 GDP by Country for 1960 (log10 scale)GDP for 1960Missing from World Bank DataNo GDP Data
In [118]:
# Year 1970
render_world_map(gdp_join_df, country_codes_trimmed_df, 1970)
GDP by Country for 1970 (log10 scale) Andorra: 7.9000 United Arab Emirates: 1.0000 Afghanistan: 9.2400 Albania: 1.0000 Armenia: 1.0000 Angola: 1.0000 Antarctica: 1.0000 Argentina: 10.5000 Austria: 10.1900 Australia: 10.6200 Azerbaijan: 1.0000 Bosnia and Herzegovina: 1.0000 Bangladesh: 9.9500 Belgium: 10.4300 Burkina Faso: 8.6600 Bulgaria: 1.0000 Bahrain: 1.0000 Burundi: 8.3900 Benin: 8.5200 Brunei Darussalam: 8.2500 Bolivia, Plurinational State of: 9.0100 Brazil: 10.6300 Bhutan: 1.0000 Botswana: 7.9800 Belarus: 1.0000 Belize: 7.7300 Canada: 10.9400 Congo, the Democratic Republic of the: 9.6900 Central African Republic: 8.2800 Congo: 8.4400 Switzerland: 1.0000 Cote d'Ivoire: 9.1600 Chile: 9.9600 Cameroon: 9.0600 China: 10.9700 Colombia: 9.8600 Costa Rica: 8.9900 Cuba: 9.7600 Cape Verde: 1.0000 Cyprus: 1.0000 Czech Republic: 1.0000 Germany: 11.3300 Djibouti: 1.0000 Denmark: 10.2300 Dominican Republic: 9.1700 Algeria: 9.6900 Ecuador: 9.4600 Estonia: 1.0000 Egypt: 9.9100 Western Sahara: 1.0000 Eritrea: 1.0000 Spain: 10.6100 Ethiopia: 1.0000 Finland: 10.0600 France: 11.1700 Gabon: 8.5100 United Kingdom: 11.1200 Georgia: 1.0000 French Guiana: 1.0000 Ghana: 9.3500 Greenland: 7.8400 Gambia: 7.7200 Guinea: 1.0000 Equatorial Guinea: 7.8200 Greece: 10.1200 Guatemala: 9.2800 Guam: 1.0000 Guinea-Bissau: 7.9000 Guyana: 8.4300 Hong Kong: 9.5800 Honduras: 8.8600 Croatia: 1.0000 Haiti: 8.5200 Hungary: 1.0000 Indonesia: 9.9600 Ireland: 9.6400 Israel: 1.0000 India: 10.8000 Iraq: 9.5200 Iran, Islamic Republic of: 10.0400 Iceland: 8.7200 Italy: 11.0500 Jamaica: 9.1500 Jordan: 8.8100 Japan: 11.3300 Kenya: 9.2100 Kyrgyzstan: 1.0000 Cambodia: 8.8600 Korea, Democratic People's Republic of: 1.0000 Korea, Republic of: 9.9500 Kuwait: 9.4600 Kazakhstan: 1.0000 Lao People's Democratic Republic: 1.0000 Lebanon: 1.0000 Liechtenstein: 7.9500 Sri Lanka: 9.3600 Liberia: 1.0000 Lesotho: 7.8400 Lithuania: 1.0000 Luxembourg: 9.1600 Latvia: 1.0000 Libyan Arab Jamahiriya: 1.0000 Morocco: 9.6000 Monaco: 8.4700 Moldova, Republic of: 1.0000 Montenegro: 1.0000 Madagascar: 9.0500 Macedonia, the former Yugoslav Republic of: 1.0000 Mali: 8.5600 Myanmar: 8.7600 Mongolia: 1.0000 Macao: 1.0000 Mauritania: 8.4900 Malta: 8.4000 Mauritius: 1.0000 Maldives: 1.0000 Malawi: 8.4600 Mexico: 10.5500 Malaysia: 9.5900 Mozambique: 1.0000 Namibia: 1.0000 Niger: 8.8100 Nigeria: 10.1000 Nicaragua: 8.8900 Netherlands: 10.5800 Norway: 10.1100 Nepal: 8.9400 New Zealand: 1.0000 Oman: 8.4100 Panama: 9.1300 Peru: 9.8700 Papua New Guinea: 8.8100 Philippines: 9.8800 Pakistan: 10.0000 Poland: 1.0000 Puerto Rico: 9.7000 Palestine, State of: 1.0000 Portugal: 9.9100 Paraguay: 8.7700 Reunion: 1.0000 Romania: 1.0000 Serbia: 1.0000 Russian Federation: 1.0000 Rwanda: 8.3400 Saudi Arabia: 9.7300 Seychelles: 7.2700 Sudan: 9.3900 Sweden: 10.5800 Singapore: 9.2800 Saint Helena, Ascension and Tristan da Cunha: 1.0000 Slovenia: 1.0000 Slovakia: 1.0000 Sierra Leone: 8.6400 San Marino: 1.0000 Senegal: 9.1100 Somalia: 8.5100 Suriname: 8.4400 Sao Tome and Principe: 1.0000 El Salvador: 9.0500 Syrian Arab Republic: 9.2500 Swaziland: 8.0500 Chad: 8.6700 Togo: 8.4000 Thailand: 9.8500 Tajikistan: 1.0000 Timor-Leste: 1.0000 Turkmenistan: 1.0000 Tunisia: 9.1600 Turkey: 10.2300 Taiwan, Province of China: 1.0000 Tanzania, United Republic of: 1.0000 Ukraine: 1.0000 Uganda: 9.1000 United States: 12.0300 Uruguay: 9.3300 Uzbekistan: 1.0000 Holy See (Vatican City State): 1.0000 Venezuela, Bolivarian Republic of: 10.0600 Viet Nam: 1.0000 Yemen: 1.0000 Mayotte: 1.0000 South Africa: 10.3300 Zambia: 9.2600 Zimbabwe: 9.2800 GDP by Country for 1970 (log10 scale)GDP for 1970Missing from World Bank DataNo GDP Data
In [119]:
# Year 2000
render_world_map(gdp_join_df, country_codes_trimmed_df, 2000)
GDP by Country for 2000 (log10 scale) Andorra: 9.1600 United Arab Emirates: 11.0200 Afghanistan: 1.0000 Albania: 9.5400 Armenia: 9.2800 Angola: 9.9600 Antarctica: 1.0000 Argentina: 11.4500 Austria: 11.3000 Australia: 11.6200 Azerbaijan: 9.7200 Bosnia and Herzegovina: 9.7500 Bangladesh: 10.7300 Belgium: 11.3700 Burkina Faso: 9.4700 Bulgaria: 10.1200 Bahrain: 9.9600 Burundi: 8.9400 Benin: 9.5500 Brunei Darussalam: 9.7800 Bolivia, Plurinational State of: 9.9200 Brazil: 11.8200 Bhutan: 8.6300 Botswana: 9.7600 Belarus: 10.1100 Belize: 8.9200 Canada: 11.8700 Congo, the Democratic Republic of the: 10.2800 Central African Republic: 8.9600 Congo: 9.5100 Switzerland: 11.4500 Cote d'Ivoire: 10.2200 Chile: 10.8900 Cameroon: 10.0200 China: 12.0800 Colombia: 11.0000 Costa Rica: 10.1800 Cuba: 10.4900 Cape Verde: 8.7300 Cyprus: 10.0000 Czech Republic: 10.7900 Germany: 12.2900 Djibouti: 8.7400 Denmark: 11.2200 Dominican Republic: 10.3900 Algeria: 10.7400 Ecuador: 10.2600 Estonia: 9.7500 Egypt: 11.0000 Western Sahara: 1.0000 Eritrea: 8.8500 Spain: 11.7800 Ethiopia: 9.9200 Finland: 11.1000 France: 12.1400 Gabon: 9.7100 United Kingdom: 12.2200 Georgia: 9.4900 French Guiana: 1.0000 Ghana: 9.7000 Greenland: 9.0300 Gambia: 8.8900 Guinea: 9.4800 Equatorial Guinea: 9.0200 Greece: 11.1200 Guatemala: 10.2900 Guam: 1.0000 Guinea-Bissau: 8.5700 Guyana: 8.8500 Hong Kong: 11.2300 Honduras: 9.8600 Croatia: 10.3400 Haiti: 9.8300 Hungary: 10.6700 Indonesia: 11.2200 Ireland: 11.0000 Israel: 11.1200 India: 11.6700 Iraq: 10.6800 Iran, Islamic Republic of: 11.0400 Iceland: 9.9600 Italy: 12.0600 Jamaica: 9.9500 Jordan: 9.9300 Japan: 12.7000 Kenya: 10.1000 Kyrgyzstan: 9.1400 Cambodia: 9.5600 Korea, Democratic People's Republic of: 1.0000 Korea, Republic of: 11.7600 Kuwait: 10.5800 Kazakhstan: 10.2600 Lao People's Democratic Republic: 9.2400 Lebanon: 10.2400 Liechtenstein: 9.4000 Sri Lanka: 10.2100 Liberia: 8.9400 Lesotho: 8.9500 Lithuania: 10.0600 Luxembourg: 10.3300 Latvia: 9.9000 Libyan Arab Jamahiriya: 10.5800 Morocco: 10.5900 Monaco: 9.4200 Moldova, Republic of: 9.1100 Montenegro: 8.9900 Madagascar: 9.6700 Macedonia, the former Yugoslav Republic of: 9.5800 Mali: 9.4700 Myanmar: 9.8400 Mongolia: 9.0600 Macao: 9.8300 Mauritania: 9.2500 Malta: 9.6100 Mauritius: 9.6700 Maldives: 8.8000 Malawi: 9.2400 Mexico: 11.8500 Malaysia: 10.9700 Mozambique: 9.7500 Namibia: 9.5900 Niger: 9.3500 Nigeria: 10.8400 Nicaragua: 9.7100 Netherlands: 11.6200 Norway: 11.2300 Nepal: 9.7400 New Zealand: 10.7200 Oman: 10.2900 Panama: 10.0900 Peru: 10.7100 Papua New Guinea: 9.5500 Philippines: 10.9200 Pakistan: 10.9100 Poland: 11.2400 Puerto Rico: 10.7900 Palestine, State of: 9.6300 Portugal: 11.0700 Paraguay: 9.9500 Reunion: 1.0000 Romania: 10.5700 Serbia: 9.8400 Russian Federation: 11.4100 Rwanda: 9.3200 Saudi Arabia: 11.2800 Seychelles: 8.7900 Sudan: 10.0900 Sweden: 11.4200 Singapore: 10.9800 Saint Helena, Ascension and Tristan da Cunha: 1.0000 Slovenia: 10.3100 Slovakia: 10.4700 Sierra Leone: 8.8000 San Marino: 9.0000 Senegal: 9.7800 Somalia: 1.0000 Suriname: 8.9800 Sao Tome and Principe: 1.0000 El Salvador: 10.0700 Syrian Arab Republic: 10.9100 Swaziland: 9.2400 Chad: 9.1400 Togo: 9.1700 Thailand: 11.1000 Tajikistan: 8.9300 Timor-Leste: 8.5600 Turkmenistan: 9.4600 Tunisia: 10.3300 Turkey: 11.4400 Taiwan, Province of China: 1.0000 Tanzania, United Republic of: 10.1300 Ukraine: 10.5100 Uganda: 9.7900 United States: 13.0100 Uruguay: 10.3600 Uzbekistan: 10.1400 Holy See (Vatican City State): 1.0000 Venezuela, Bolivarian Republic of: 11.0700 Viet Nam: 10.4900 Yemen: 9.9800 Mayotte: 1.0000 South Africa: 11.1800 Zambia: 9.5600 Zimbabwe: 9.8300 GDP by Country for 2000 (log10 scale)GDP for 2000Missing from World Bank DataNo GDP Data
In [120]:
# Year 2021
render_world_map(gdp_join_df, country_codes_trimmed_df, 2021)
GDP by Country for 2021 (log10 scale) Andorra: 9.5200 United Arab Emirates: 1.0000 Afghanistan: 1.0000 Albania: 10.2600 Armenia: 10.1400 Angola: 10.8600 Antarctica: 1.0000 Argentina: 11.6900 Austria: 11.6800 Australia: 12.1900 Azerbaijan: 10.7400 Bosnia and Herzegovina: 10.3500 Bangladesh: 11.6200 Belgium: 11.7800 Burkina Faso: 10.3000 Bulgaria: 10.9000 Bahrain: 10.5900 Burundi: 9.4600 Benin: 10.2500 Brunei Darussalam: 10.1500 Bolivia, Plurinational State of: 10.6100 Brazil: 12.2100 Bhutan: 1.0000 Botswana: 10.2500 Belarus: 10.8300 Belize: 9.2500 Canada: 12.3000 Congo, the Democratic Republic of the: 10.7300 Central African Republic: 9.4000 Congo: 10.1000 Switzerland: 11.9100 Cote d'Ivoire: 10.8400 Chile: 11.5000 Cameroon: 10.6600 China: 13.2500 Colombia: 11.5000 Costa Rica: 10.8100 Cuba: 1.0000 Cape Verde: 9.2900 Cyprus: 10.4400 Czech Republic: 11.4500 Germany: 12.6300 Djibouti: 9.5300 Denmark: 11.6000 Dominican Republic: 10.9700 Algeria: 11.2300 Ecuador: 11.0300 Estonia: 10.5600 Egypt: 11.6100 Western Sahara: 1.0000 Eritrea: 1.0000 Spain: 12.1500 Ethiopia: 11.0500 Finland: 11.4800 France: 12.4700 Gabon: 10.2600 United Kingdom: 12.5000 Georgia: 10.2700 French Guiana: 1.0000 Ghana: 10.8900 Greenland: 1.0000 Gambia: 9.3200 Guinea: 10.2000 Equatorial Guinea: 10.0900 Greece: 11.3300 Guatemala: 10.9300 Guam: 1.0000 Guinea-Bissau: 9.2100 Guyana: 9.8700 Hong Kong: 11.5700 Honduras: 10.4500 Croatia: 10.8300 Haiti: 10.3200 Hungary: 11.2600 Indonesia: 12.0700 Ireland: 11.7000 Israel: 11.6800 India: 12.5000 Iraq: 11.3200 Iran, Islamic Republic of: 1.0000 Iceland: 10.4100 Italy: 12.3200 Jamaica: 10.1300 Jordan: 10.6600 Japan: 12.6900 Kenya: 11.0400 Kyrgyzstan: 9.9300 Cambodia: 10.4300 Korea, Democratic People's Republic of: 1.0000 Korea, Republic of: 12.2500 Kuwait: 1.0000 Kazakhstan: 11.2800 Lao People's Democratic Republic: 10.2700 Lebanon: 10.2600 Liechtenstein: 1.0000 Sri Lanka: 10.9300 Liberia: 9.5400 Lesotho: 9.4000 Lithuania: 10.8200 Luxembourg: 10.9400 Latvia: 10.5900 Libyan Arab Jamahiriya: 10.6200 Morocco: 11.1200 Monaco: 1.0000 Moldova, Republic of: 10.1400 Montenegro: 9.7600 Madagascar: 10.1700 Macedonia, the former Yugoslav Republic of: 10.1400 Mali: 10.2800 Myanmar: 10.8100 Mongolia: 10.1800 Macao: 10.4800 Mauritania: 9.9200 Malta: 10.2400 Mauritius: 10.0500 Maldives: 9.6900 Malawi: 10.1000 Mexico: 12.1100 Malaysia: 11.5700 Mozambique: 10.2100 Namibia: 10.0900 Niger: 10.1700 Nigeria: 11.6400 Nicaragua: 10.1500 Netherlands: 12.0100 Norway: 11.6800 Nepal: 10.5600 New Zealand: 11.4000 Oman: 10.9300 Panama: 10.8000 Peru: 11.3500 Papua New Guinea: 10.4200 Philippines: 11.6000 Pakistan: 11.5400 Poland: 11.8300 Puerto Rico: 1.0000 Palestine, State of: 10.2600 Portugal: 11.4000 Paraguay: 10.5900 Reunion: 1.0000 Romania: 11.4500 Serbia: 10.8000 Russian Federation: 12.2500 Rwanda: 10.0400 Saudi Arabia: 11.9200 Seychelles: 9.1200 Sudan: 10.5400 Sweden: 11.8000 Singapore: 11.6000 Saint Helena, Ascension and Tristan da Cunha: 1.0000 Slovenia: 10.7900 Slovakia: 11.0600 Sierra Leone: 9.6200 San Marino: 1.0000 Senegal: 10.4400 Somalia: 9.8600 Suriname: 9.4600 Sao Tome and Principe: 8.7400 El Salvador: 10.4600 Syrian Arab Republic: 1.0000 Swaziland: 9.6900 Chad: 10.0700 Togo: 9.9200 Thailand: 11.7000 Tajikistan: 9.9400 Timor-Leste: 9.2900 Turkmenistan: 1.0000 Tunisia: 10.6700 Turkey: 11.9100 Taiwan, Province of China: 1.0000 Tanzania, United Republic of: 10.8300 Ukraine: 11.3000 Uganda: 10.6100 United States: 13.3600 Uruguay: 10.7700 Uzbekistan: 10.8400 Holy See (Vatican City State): 1.0000 Venezuela, Bolivarian Republic of: 1.0000 Viet Nam: 11.5600 Yemen: 10.3200 Mayotte: 1.0000 South Africa: 11.6200 Zambia: 10.3300 Zimbabwe: 10.4200 GDP by Country for 2021 (log10 scale)GDP for 2021Missing from World Bank DataNo GDP Data

Insights¶

The main insights drawn from the analysis of the GDP over time plots are:

  • All G7 countries, except for Japan experienced a drop in their GDP following the onset of the global economic and financial crisis in 2008.
  • The GDP for USA bounced back in 2010 and increased steadily up to 2019, before the onset of the Covid-19 pandemic.
  • The GDP growth for Canada, France, Germany, Italy and the UK has slowed down after the financial crisis of 2008 and has not recovered since.

The main insights drawn from the analysis of world map GDP plots are:

  • The number of countries where the World bank has no GDP data (marked in green on the world map) has been steadily decreasing since 1960.
  • There are 8 country codes in Pygal that have no match against the World Bank GDP data country codes - these are marked in blue on the world map and are listed below:
    • Antarctica
    • Western Sahara
    • French Guiana, Reunion and Mayotte
    • Saint Helena, Ascension and Tristan da Cunha
    • Taiwan
    • The Holy See.
  • There are 40 country codes in the World Bank GDP data that have no correspondence to the Pygal country codes. These codes correspond to countries (e.g. Qatar, Faroe Islands, South Sudan, etc), overseas territories or regions of countries. For some of these country codes, GDP data have not been recorded by the World Bank.